/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kurvykurvy.image;

import com.kurvykurvy.page.ImageFrame;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import org.netbeans.api.visual.widget.ImageWidget;
import org.netbeans.api.visual.widget.Scene;

/**
 *
 * @author HY
 */
public class ImageFrameWidget
    extends ImageWidget
{
    ImageFrame imageFrame;

    public ImageFrameWidget( Scene scene )
    {
        super( scene );
    }

    public ImageFrameWidget( Scene scene, ImageFrame frame )
    {
        super( scene );
        setImageFrame( frame );
    }

    public void setImageFrame( ImageFrame frame )
    {
        imageFrame = frame;
        if( frame.getImage() != null )
            this.setImage( frame.getImage() );
        else
        {
            BufferedImage dummyImage = new BufferedImage( frame.getSize().width, frame.getSize().height, BufferedImage.TYPE_INT_ARGB );
            Graphics2D g2 = dummyImage.createGraphics();
            g2.setColor( Color.BLUE );
            g2.fillRect( 0, 0, frame.getSize().width, frame.getSize().height );
            g2.dispose();
            this.setImage( dummyImage );
        }
        this.setCheckClipping( true );
        this.setMaximumSize( frame.getSize() );
        this.setPreferredSize( frame.getSize() );
        this.setPreferredLocation( frame.getOffset() );
    }

    @Override
    public void setImage( Image img )
    {
        if( img instanceof BufferedImage )
        {
            this.imageFrame.setLoadedImage(  new LoadedImage( (BufferedImage) img ) );
        }
        super.setImage( img );
    }

    public void setImage( LoadedImage img )
    {
        this.imageFrame.setLoadedImage( img );
        super.setImage( img.getImage() );
    }

    public class ImageFrameAcceptProvider
    {
        
    }
}
